<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
include('../config.php');
include('../libraries/dao.php');
dbConnect($cfg['db']['dsn']);
function createCategory($id=0)
{
    global $cfg;
    $categories = dbFetchAll('select id,parent_id,name,active from categories where active=1 and parent_id='.$id);
    if(count($categories)==0) return '';
    $html = ($id==0)?'<ul class="menu" id="menu">':'<ul>';
    foreach($categories as $col=>$data)
    {        
        $html .= ($id==0)?'<li><a href="'.$cfg['site']['base_url'].'category/'.$data['name'].'" class="menulink">'.$data['name'].'</a>':'<li><a href="'.$cfg['site']['base_url'].'/category/'.$data['name'].'">'.$data['name'].'</a>';
        $html .= createCategory($data['id']);
        $html .= '</li>';
    }
    $html .= '</ul>';
    return $html;
}
$html = createCategory();
$fp = fopen('../menu.php', 'w');
fwrite($fp, $html);
fclose($fp);
?>
